package com.highper.common.entity.response;

import com.highper.common.constant.ResponseCodeConstant;
import com.highper.common.globalization.Globalization;

import java.io.Serializable;
import java.util.HashMap;

/**
 * @Author ZhangGJ
 * @Date 2022/01/25 10:05
 */
public class HighperResponse extends HashMap<String, Object> implements Serializable {

    private static final long serialVersionUID = -4154635707792169653L;

    private static final HighperResponse MAP = new HighperResponse();

    public static HighperResponse result(int rows) {
        return rows > 0 ? success() : failure();
    }

    public static HighperResponse result(boolean b) {
        return b ? success() : failure();
    }

    public static HighperResponse resultWebFlux(int rows) {
        return rows > 0 ? successWebFlux() : failureWebFlux();
    }

    public static HighperResponse resultWebFlux(boolean b) {
        return b ? successWebFlux() : failureWebFlux();
    }

    public static HighperResponse success() {
        HighperResponse response = new HighperResponse();
        response.put("code", ResponseCodeConstant.SUCCESS);
        response.put("message", Globalization.language("response-success"));
        return response;
    }

    public static HighperResponse successWebFlux() {
        HighperResponse response = new HighperResponse();
        response.put("code", ResponseCodeConstant.SUCCESS);
        response.put("message", Globalization.languageWebFlux("response-success"));
        return response;
    }

    public static HighperResponse success(int code, String message) {
        HighperResponse response = new HighperResponse();
        response.put("code", code);
        response.put("message", message);
        return response;
    }

    public static HighperResponse failure() {
        HighperResponse response = new HighperResponse();
        response.put("code", ResponseCodeConstant.FAILURE);
        response.put("message", Globalization.language("response-success"));
        return response;
    }

    public static HighperResponse failureWebFlux() {
        HighperResponse response = new HighperResponse();
        response.put("code", ResponseCodeConstant.FAILURE);
        response.put("message", Globalization.languageWebFlux("response-success"));
        return response;
    }

    public static HighperResponse failure(int code, String message) {
        HighperResponse response = new HighperResponse();
        response.put("code", code);
        response.put("message", message);
        return response;
    }

    public static HighperResponse data(Object data) {
        MAP.put("code", ResponseCodeConstant.SUCCESS);
        MAP.put("data", data);
        return MAP;
    }
}
